local yeXingzhen = fk.CreateSkill {
  name = "ye__xingzhen",
  tags = { Skill.Permanent },
}
Fk:loadTranslationTable{
  ["ye__xingzhen"] = "星阵",
  [":ye__xingzhen"] = "持恒技。牌堆顶的7张牌始终为你可见，你的回合外，你可以如手牌般使用或打出其中的基本牌，你的回合内，你可以如手牌般使用或打出其中的锦囊牌。",

  ["@[ye__xingzhen]"] = "星阵",
  ["#ye__xingzhen"] = "星阵：你可以使用或打出其中你需要的基本牌或锦囊牌",
}

Fk:addQmlMark {
  name = "ye__xingzhen",
  how_to_show = function(name, value, p)
    return tostring(value)
  end,
  qml_data = function(name, value, p)
    if type(value) ~= "number" or value < 1 then return {} end
    local drawPile = Fk:currentRoom().draw_pile
    local cards = {}
    for i = 1, math.min(value, #drawPile), 1 do
      table.insert(cards, drawPile[i])
    end
    return cards
  end,
  qml_path = function(name, value, p)
    if Self:isBuddy(p) and p:hasSkill(yeXingzhen.name) then
      return "packages/utility/qml/ViewPile"
    end
    return ""
  end,
}
yeXingzhen:addAcquireEffect(function(self, player)
  player.room:setPlayerMark(player, "@[ye__xingzhen]", 7)
end)

yeXingzhen:addLoseEffect(function(self, player)
  player.room:setPlayerMark(player, "@[ye__xingzhen]", 0)
end)

yeXingzhen:addEffect("viewas", {
  anim_type = "control",
  pattern = ".|.|.|.|.",
  prompt = "#ye__xingzhen",
  expand_pile = function(self, player)
    local ids = {}
    for i = 1, 7, 1 do
      if i > #Fk:currentRoom().draw_pile then break end
      table.insert(ids, Fk:currentRoom().draw_pile[i])
    end
    return ids
  end,
  filter_pattern = {
    min_num = 1,
    max_num = 1,
    pattern = ".",
  },
  card_filter = function(self, player, to_select, selected)
    if #selected == 0
        and table.contains(Fk:currentRoom().draw_pile, to_select)
        and (
          (Fk:currentRoom().current == player and (Fk:getCardById(to_select).type == Card.TypeTrick))
          or
          (Fk:currentRoom().current ~= player and Fk:getCardById(to_select).type == Card.TypeBasic)
        ) then
      local card = Fk:getCardById(to_select)
      if Fk.currentResponsePattern == nil then
        return player:canUse(card) and not player:prohibitUse(card)
      else
        return Exppattern:Parse(Fk.currentResponsePattern):match(card)
      end
    end
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    return Fk:getCardById(cards[1])
  end,
  enabled_at_use = function(self, player, response)
    return #player:getViewAsCardNames(yeXingzhen.name, Fk:getAllCardNames("btde")) > 0
  end,
  enabled_at_response = function(self, player, response)
    return #player:getViewAsCardNames(yeXingzhen.name, Fk:getAllCardNames("btde")) > 0
  end,
})

yeXingzhen:addEffect("filter", {
  handly_cards = function(self, player)
    local room = Fk:currentRoom()
    local cards
    if player:hasSkill(yeXingzhen.name) then
      if room.current == player then
        cards = table.filter(table.slice(room.draw_pile, 1, 8), function(element, index, array)
          return Fk:getCardById(element).type == Card.TypeTrick
        end)
      else
        cards = table.filter(table.slice(room.draw_pile, 1, 8), function(element, index, array)
          return Fk:getCardById(element).type == Card.TypeBasic
        end)
      end
    end
    return cards
  end,
})
return yeXingzhen
